package com.ant.storage.controller;

import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.PlatformDto;
import com.ant.storage.pojo.PlatformMsg;
import com.ant.storage.service.IPlatformMsgService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzd
 * @since 2023-07-24
 */
@RestController
@RequestMapping("/platform-msg")
public class PlatformMsgController {

    @Autowired
    private IPlatformMsgService platformMsgService;

    @ApiOperation("获取分页信息")
    @GetMapping("/getPlatformMsgPage")
    public ResultPage getPlatformMsgPage(PlatformDto dto){
        PageInfo<PlatformMsg> pageList = platformMsgService.queryAllByPage(dto);
        return ResultPage.success("获取成功",pageList);
    }


    @ApiOperation("获取分页信息")
    @PostMapping("/save")
    public ResultVo save(@RequestBody PlatformMsg msg){
        msg.setCreateTime(new Date());
        if(msg.getId()!=null){
            return ResultVo.success("操作成功", platformMsgService.updateById(msg));
        }
        return ResultVo.success("操作成功", platformMsgService.save(msg));
    }

    @ApiOperation("获取商品id获取商品详细信息")
    @GetMapping("/getPlatformMsgById/{id}")
    public ResultVo<Object> getById(@PathVariable(value = "id",required = false) Integer id) throws ParseException {
        PlatformMsg msg = platformMsgService.getById(id);
        return ResultVo.success(msg);
    }


    @ApiOperation("获取分页信息")
    @GetMapping("/updateById")
    public ResultVo<Object> updateById(PlatformMsg msg){
        return ResultVo.success("操作成功",platformMsgService.updateById(msg));
    }

    @ApiOperation("删除")
    @GetMapping("/del/{id}")
    public ResultVo<Object> del(@PathVariable("id") Integer id){
        PlatformMsg msg=new PlatformMsg();
        msg.setId(id);
        msg.setIsDel(0);
        return ResultVo.success("操作成功",platformMsgService.updateById(msg));
    }
}
